package edu.gatech.cs2340.mule.view;

import java.awt.Color;
import java.awt.GridLayout;

import javax.swing.JLabel;
import javax.swing.JPanel;

import edu.gatech.cs2340.mule.model.Player;
import edu.gatech.cs2340.mule.presenter.MuleGamePresenter;

/**
 * This class represents the panel on the lefthand side of the screen.
 * It holds the scoreboard and last round's production.
 * 
 * @author Zach Elliott
 *
 */
public class ScoreboardPanel extends JPanel {
	
	private ScorePanel scorePanel;
	private ProductionPanel productionPanel;
	
	/**
	 * Initialize the panel.
	 */
	public ScoreboardPanel() {
		GridLayout layout = new GridLayout(3, 1);
		layout.setVgap(10);
		setLayout(layout);
		setBackground(MuleGamePresenter.BACKGROUND_COLOR);
		setForeground(MuleGamePresenter.FOREGROUND_COLOR);
		
		scorePanel = new ScorePanel();
		add(scorePanel);
		
		JLabel scoreLabel = new JLabel("<html><font size=+1>Last Round's Production");
		scoreLabel.setBackground(MuleGamePresenter.BACKGROUND_COLOR);
		scoreLabel.setForeground(MuleGamePresenter.FOREGROUND_COLOR);
		add(scoreLabel);
		
		productionPanel = new ProductionPanel();
		add(productionPanel);
	}
	
	/**
	 * Updates the scoreboard based on current player order
	 * @param players array of players in ascending score order
	 */
	public void updateScoreboard(Player[] players) {
		scorePanel.updateScoreboard(players);
	}
	
	/**
	 * Updates the production panel to reflect last round's production
	 * for the given player
	 * @param production array of size 3 holding each increase in resources
	 * for the player since last round
	 * @param currentPlayer the player which the production belongs to
	 */
	public void updateProductionPanel(int[] production, int currentPlayer) {
		productionPanel.updateProductionPanel(production, currentPlayer);
	}
	
	/**
	 * Colors the production panel according to the players'
	 * chosen colors
	 * @param players
	 */
	public void colorProductionPanel(Player[] players) {
		productionPanel.colorProductionPanel(players);
	}
}
